package com.gxa.modules.service.impl;

import com.gxa.common.vo.ResultVo;
import com.gxa.modules.mapper.OrdersMapper;
import com.gxa.modules.service.OrdersService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class OrdersServiceImpl implements OrdersService {
    @Autowired(required = false)
    private OrdersMapper ordersMapper;
    @Override
    public ResultVo queryOrdersList(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> maps=ordersMapper.queryOrdersList(param1,param2);
        resultVo.setCode(200);
        resultVo.setData(maps);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo queryByOr_status4(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> maps=ordersMapper.queryByOr_status4(param1,param2);
        resultVo.setCode(200);
        resultVo.setData(maps);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo queryByOr_status1(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> maps=ordersMapper.queryByOr_status1(param1,param2);
        resultVo.setCode(200);
        resultVo.setData(maps);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo queryByOr_status23(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> maps=ordersMapper.queryByOr_status23(param1,param2);
        resultVo.setCode(200);
        resultVo.setData(maps);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo searchByOrders(Integer currentPage, Integer pageSize, String conn) {
        ResultVo resultVo=new ResultVo();
        int result=ordersMapper.countByOr_id(conn);
        if(result>0){
            Integer param1=(currentPage-1)*pageSize;
            Integer param2=pageSize;
            List<Map> maps=ordersMapper.searchByOrders(param1,param2,conn);
            resultVo.setCode(200);
            resultVo.setData(maps);
            resultVo.setMsg("查询成功");
        }else{
            result=ordersMapper.countByRegion(conn);
            if(result>0){
                Integer param1=(currentPage-1)*pageSize;
                Integer param2=pageSize;
                List<Map> maps=ordersMapper.searchByRegion(param1,param2,conn);
                resultVo.setCode(200);
                resultVo.setData(maps);
                resultVo.setMsg("查询成功");
            }else{
                result=ordersMapper.countByShop(conn);
                if(result>0){
                    Integer param1=(currentPage-1)*pageSize;
                    Integer param2=pageSize;
                    List<Map> maps=ordersMapper.searchByShop (param1,param2,conn);
                    resultVo.setCode(200);
                    resultVo.setData(maps);
                    resultVo.setMsg("查询成功");
                }
            }
        }

        return resultVo;
    }

    @Override
    public ResultVo queryShouHou(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> maps=ordersMapper.queryShouHou(param1,param2);
        Integer returnMoney = ordersMapper.queryReturnMoney();
        Integer returnOrders=ordersMapper.queryReturnOrders();
        List list=new ArrayList();
        list.add(maps);
        list.add(returnMoney);
        list.add(returnOrders);
        resultVo.setCode(200);
        resultVo.setData(list);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo queryRefund(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> maps=ordersMapper.queryRefund(param1,param2);
        resultVo.setCode(200);
        resultVo.setData(maps);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo queryRestMoney(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> maps=ordersMapper.queryRestMoney(param1,param2);
        resultVo.setCode(200);
        resultVo.setData(maps);
        resultVo.setMsg("查询成功");
        return resultVo;
    }


}

